﻿using BCCommon.Enums;
using BCCommon.TMS.Order;
using BCEntity.Sim.Admin.Admin;
using BCEntity.TMS.Order.OrderPool;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace BCData.TMS.Order.OrderPool
{
    /// <summary>
    /// 订单池
    /// </summary>
    public interface IOrderPoolData
    {
        /// <summary>
        /// 创建订单池订单记录
        /// </summary>
        /// <param name="entity">订单池记录</param>
        /// <returns></returns>
        Task<OrderPoolEntity> Add(OrderPoolEntity entity);
        /// <summary>
        /// 获取订单池信息
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<OrderPoolEntity> Get(long orderId);

        /// <summary>
        /// 获取订单池需指派订单列表
        /// </summary>
        /// <param name="adminId">管理员Id</param>
        /// <param name="provinceCode">省份编码</param>
        /// <param name="cityCode">城市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="handleStatus">指派处理状态</param>
        /// <param name="driverId">司机Id</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param> 
        /// <param name="ascending">升序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderPoolEntity>, int)> Query(long? adminId, string provinceCode, string cityCode, string countyCode, OrderAssignHandleStatus? handleStatus, long? driverId, DateTime? start, DateTime? end, bool? ascending, int pageIndex, int pageSize);
       
        Task<(IEnumerable<OrderPoolEntity>, int)> Query(List<long> listAdminId, string provinceId, string communityId, string countyId, OrderAssignHandleStatus? handleStatus, long? driverId, DateTime? start, DateTime? end, bool? ascending, int pageIndex, int pageSize);
      
        /// <summary>
        /// 重置超时未接单的订单
        /// </summary>
        /// <returns></returns>
        void UpdateTimeOutOrderAndClearAssign();

        /// <summary>
        /// 更新指派状态为进行中
        /// </summary>
        /// <param name="AdminId">操作人Id</param>
        /// <param name="editer">操作人</param>
        /// <param name="orderId">订单Id</param>
        /// <param name="driverId">司机Id</param>
        /// <param name="vehicleNo">车牌号</param>
        /// <param name="distance">距离</param>
        /// <returns></returns>
        Task<bool> UpdateStatusProcessing(long AdminId,string editer, long orderId,long driverId, string vehicleNo, double distance);

        /// <summary>
        /// 更新指派状态为完成
        /// driverId等于空时，是订单被取消了
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="driverId">司机Id</param>
        /// <returns></returns>
        Task<bool> UpdateStatusDone(long orderId,long? driverId);
        /// <summary>
        /// 修改是否指派已就绪
        /// </summary>
        /// <param name="orderId">订单id</param>
        /// <returns></returns>
        Task<bool> UpdateIsAssignReady(long orderId);
        /// <summary>
        /// 司机接单后
        /// 关闭订单在订单池的指派状态
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> ClearOrderAssign(long orderId);
       
        /// <summary>
        /// 取消订单不关联归属查询订单池订单
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<OrderPoolEntity> GetCancelOrder(long orderId);

        /// <summary>
        /// 获取订单成交量的数据
        /// </summary>
        /// <param name="companyId">公司ID</param>
        /// <param name="departmentId">部门ID</param>
        /// <param name="listAdminId">人员ID</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="assignStatus">订单指派状态</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderPoolEntity>, int)> GetOrderPoolStatisticsAsync(int? companyId,int? departmentId, List<long> listAdminId, DateTime? start, DateTime? end, OrderAssignHandleStatus? assignStatus, int pageIndex, int pageSize);

        ///// <summary>
        ///// 查询公司管理者所拥有的下属人员
        ///// </summary>
        ///// <param name="companyId">公司ID</param>
        ///// <returns></returns>
        //Task<IEnumerable<AdminEntity>> GetIsMainAdminIds(int companyId);

        ///// <summary>
        ///// 查询部门负责人所拥有的下属
        ///// </summary>
        ///// <param name="departmentId">部门ID</param>
        ///// <returns></returns>
        //Task<IEnumerable<DepartmentStaffEntity>> GetPrincipalAdminIdsAsync(int departmentId);

        /// <summary>
        /// 获取指派订单列表
        /// </summary>
        /// <param name="handleStatus">指派处理状态</param>
        /// <param name="driverId">司机Id</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderPoolEntity>, int)> QueryDriverOrders(OrderAssignHandleStatus? processing, long driverId, int pageIndex, int pageSize);

        /// <summary>
        /// 修改订单已接单
        /// </summary>
        /// <param name="orderId">订单id</param>
        /// <returns></returns>
        Task<bool> UpdateOrderReceived(long orderId);
    }
}
